<?php ob_start();?>
<html>
<?php 
	$root = $_SERVER['DOCUMENT_ROOT'];
 	include($root.'/standart/head.php');
 	include($root.'/standart/dateHeader.php');
 	include($root.'/standart/checkUser.php');
?>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Geveze Cafe | Siparişler</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="../css/sb-admin.css" rel="stylesheet">
    <link href="../css/tinyBox.css" rel="stylesheet" type="text/css" media="screen"/>
    <link href="../css/jquery-ui-1.10.4.css" rel="stylesheet" type="text/css" media="screen"/>
	<link href="../css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">

	<script type="text/javascript">

	var btnClicked = false;
	function updateIsPrint(orderID){
		btnClicked = true;
		parent.loadPageX();
		$.ajax({
			url: "updateOrders.php",
			type: "POST",
			data:  "orderId="+orderID,
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			success: function(data, textStatus, jqXHR)
			{
			},
			complete: function() {
				parent.unloadPageX();
				listOrders();
				
            }
            });
	}

	var results = [];

	function openNewUnit(_url) {
		TINY.box.show({html:_url,width:800,height:600,opacity:20,topsplit:3});
	}

	function closeBox() {
		TINY.box.hide();
	}
	
		function loadPage() {
				$.datepicker.setDefaults($.datepicker.regional['tr']); 
				$.datepicker.setDefaults({ dateFormat: 'dd/mm/yy' });
				$('.datepicker').datepicker();
				listOrders();
				parent.unloadPageX();
				setInterval(function(){listOrders()}, 30000);
		}

		function listOrders(){
			url = 'getOrderList.php';				
			$('.table-responsive').html(ajx(url, ''));
			var table = $('#dataTables-example').dataTable({
	            "language": {
	                "url": "../css/plugins/dataTables/dataTablesTurkish.json"
	            },
				"footerCallback": function ( row, data, start, end, display ) {
		            var api = this.api();
		            // Remove the formatting to get integer data for summation
		            var intVal = function ( i ) {
		                return typeof i === 'string' ?
		                    i.replace(/[\$,]/g, '')*1 :
		                    typeof i === 'number' ?
		                        i : 0;
		            };
		 
		            // Total over all pages
		            var total = api
		                .column( 6 )
		                .data()
		                .reduce( function (a, b) {
		                    return parseFloat(a) + parseFloat(b);
		                } );
		 
		            // Total over this page
		            pageTotal = 0;
		            var pageTotal = api
		                .column( 6, { page: 'current'} )
		                .data()
		                .reduce( function (a, b) {
		                    return parseFloat(a) + parseFloat(b);
		                } );
		 
		            // Update footer
		            $( api.column(6).footer() ).html(
		                ''+parseFloat(pageTotal).toFixed(2) +' TL'
		            );
// 		            $( api.column(8 ).footer() ).html(
// 			                total.toFixed(2) +' TL'
// 			            );
					document.getElementById('genelToplam').innerHTML = parseFloat(total).toFixed(2) +' TL';
		        }
	        } );

			$('#dataTables-example tbody').on( 'click', 'tr', function () {
				if(btnClicked){
					btnClicked = false;
					return;
				}
				$(this).addClass('selected');
	            row = $(this).find("td");
	            if(results[row[0].innerText]!=null){
	            	openNewUnit(results[row[0].innerText]);
	            }else{
		            url = 'getOrdersItem.php?report=1'
						+'&order_id='+row[0].innerText;
	            	parent.loadPageX();
					ajx(url, "fillPopup");
	            }
			});

		}

		function fillPopup(res){
			openNewUnit(res);
            results[row[0].innerText]=res;
            parent.unloadPageX();
		}
	</script>

	
	
</head>	
	

	<body onload="loadPage()">
    <div id="wrapper">
        <div id="inner-page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Sipariş Raporu</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <!-- /.col-lg-12 -->
                <div class="col-lg-12">
                	<div class="panel panel-default">
                        <div class="panel-body">
                        	<div class="row">
                            </div>
                        	<div class="table-responsive">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.row -->
        </div>
        <!-- /#page-wrapper -->
		
    </div>
    <!-- /#wrapper -->
    <!-- Core Scripts - Include with every page -->
    <!-- Page-Level Demo Scripts - Forms - Use for reference -->
</body>
    <script type="text/javascript" src="../js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="../js/ajax.js"></script>
    <script type="text/javascript" src="../js/tinybox.js"></script>
    <script type="text/javascript" src="../js/jquery-ui-1.10.4.js"></script>
    <script type="text/javascript" src="../js/plugins/dataTables/jquery.dataTables.js"></script>
    <script type="text/javascript" src="../js/plugins/dataTables/dataTables.bootstrap.js"></script>
</html>
<?php ob_end_flush(); ?>